package com.neusoft.yuejian_01.adapter;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.yuejian_01.activity.SetPictureInfoActivity;
import com.neusoft.yuejian_01.model.ConstPhoto;
import com.neusoft.yuejian_01.viewHolder.SetPictureListViewHolder;
import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.javabean.SetPictureBean;

import java.util.ArrayList;
import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;
/**
 * Created by Administrator on 2017/10/9.
 */

public class SetPicturelistAdapter extends RecyclerView.Adapter {

    private List<SetPictureBean> SetPicturelist = new ArrayList<>();
    private Context context;
    private LayoutInflater layoutInflater;//使用了LayoutInflater来载入布局界面
    public SetPicturelistAdapter(Context context, List<SetPictureBean> SetPicturelist) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.SetPicturelist.addAll(SetPicturelist);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView=layoutInflater.inflate(R.layout.item_set_picture,parent,false);
        SetPictureListViewHolder holder=new SetPictureListViewHolder(itemView);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {


        SetPictureListViewHolder setPictureListViewHolder=( SetPictureListViewHolder) holder;
        final SetPictureBean setPictureBean = SetPicturelist.get(position);

        final String postTitle =setPictureBean.getP_title();
        String touxiang= ConstPhoto.BASE_URL+ConstPhoto.SetPictureFile+ setPictureBean.getU_pic();
        String pic0 =  ConstPhoto.BASE_URL+ConstPhoto.SetPicturePFile+ setPictureBean.getP_pic0();
        String pic1= ConstPhoto.BASE_URL+ConstPhoto.SetPicturePFile+setPictureBean.getP_pic1();
        String postclub=setPictureBean.getC_name();
        String postpeople=setPictureBean.getU_name();
        String posttime=setPictureBean.getP_createtime();
        int  postId=setPictureBean.getU_id();
        Picasso.with(context)
                .load(touxiang)
                .into(setPictureListViewHolder.setPicturetouxiang);
        Picasso.with(context)
                .load(pic0)
                .into(setPictureListViewHolder.setPictureimage);
        Picasso.with(context)
                .load(pic1)
                .into(setPictureListViewHolder.setPictureimagea);



        setPictureListViewHolder.setPicturetitle.setText(postTitle);
        setPictureListViewHolder. setPictureName.setText(postclub);
        setPictureListViewHolder.setPicturetUserName.setText(postpeople);
        setPictureListViewHolder.setPicturetime.setText(posttime);


//跳转看详情
      setPictureListViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Bundle bundle=new Bundle();
                bundle.putInt("p_id",setPictureBean.getP_id());
                bundle.putInt("c_id",setPictureBean.getC_id());
                bundle.putString("p_title",setPictureBean.getP_title());
                bundle.putString("p_info",setPictureBean.getP_info());
                bundle.putString("p_createtime",setPictureBean.getP_createtime());
                bundle.putString("p_pic",setPictureBean.getP_pic0());
                bundle.putString("p_pic1",setPictureBean.getP_pic1());
                bundle.putString("p_pic2",setPictureBean.getP_pic2());
                bundle.putString("p_pic3",setPictureBean.getP_pic3());
                bundle.putString("u_pic",setPictureBean.getU_pic());
                bundle.putString("c_name",setPictureBean.getC_name());
                bundle.putString("u_name",setPictureBean.getU_name());
                Intent intent = new Intent(context, SetPictureInfoActivity.class);
                intent.putExtras(bundle);
                context.startActivity(intent);

                //启动新的activity(帖子详情)
            }
        });




    }

    @Override
    public int getItemCount() {
        return SetPicturelist.size();
    }
}